<?php
if (!file_exists('../install.lock')) {
    header('Location: ../install.php');
    exit;
}
session_start();
require_once '../config.php';

// 获取系统设置
$settings = getSettings();
// 检查是否登录
if (!isset($_SESSION['admin_id'])) {
    header('Location: login.php');
    exit;
}

// 获取管理员信息
$stmt = $pdo->prepare("SELECT * FROM admins WHERE id = ?");
$stmt->execute([$_SESSION['admin_id']]);
$admin = $stmt->fetch();

// 获取统计数据
$stats = [
    'total_kami' => $pdo->query("SELECT COUNT(*) FROM kami")->fetchColumn(),
    'active_kami' => $pdo->query("SELECT COUNT(*) FROM kami WHERE status = 1")->fetchColumn(),
    'used_kami' => $pdo->query("SELECT COUNT(*) FROM kami WHERE use_count > 0")->fetchColumn(),
    'total_logs' => $pdo->query("SELECT COUNT(*) FROM qq_access_logs")->fetchColumn()
];

// 获取最近生成的卡密
$recent_cards = $pdo->query("SELECT kami_key, expire_time, use_count, status, type, first_use_time, create_time FROM kami ORDER BY create_time DESC LIMIT 10")->fetchAll();

// 获取最近查询记录
$recent_logs = $pdo->query("SELECT qq, phone, phonediqu, longitude, latitude, region, ip, created_at FROM qq_access_logs ORDER BY created_at DESC LIMIT 10")->fetchAll();

// 设置变量供模板使用
$total_cards = $stats['total_kami'];
$used_cards = $stats['used_kami'];
$unused_cards = $stats['active_kami'] - $stats['used_kami'];
$total_logs = $stats['total_logs'];

// 当前版本号
require_once 'version.php';

// 获取最新版本信息
function getLatestVersion() {
    $gitee_api_url = 'https://gitee.com/api/v5/repos/initialqqq/initial-sms/releases/latest';
    $latest_version = '未知';
    $update_url = 'https://gitee.com/initialqqq/initial-sms';
    $update_log = '无法获取更新日志';
    $download_url = '';
    
    try {
        $options = [
            'http' => [
                'method' => 'GET',
                'header' => [
                    'User-Agent: PHP'
                ],
                'timeout' => 5
            ]
        ];
        $context = stream_context_create($options);
        $response = @file_get_contents($gitee_api_url, false, $context);
        
        if ($response !== false) {
            $release_info = json_decode($response, true);
            if (isset($release_info['tag_name'])) {
                $latest_version = $release_info['tag_name'];
                $update_log = $release_info['body'] ?? '无更新日志';
                $update_url = $release_info['html_url'] ?? 'https://gitee.com/initialqqq/initial-sms';
                
                // 构建更新包下载链接
                $version_no_v = ltrim($latest_version, 'Vv');
                $download_url = "https://gitee.com/initialqqq/initial-sms/releases/download/{$latest_version}/update.zip";
            }
        }
    } catch (Exception $e) {
        // 忽略错误
    }
    
    return [
        'version' => $latest_version,
        'update_log' => $update_log,
        'update_url' => $update_url,
        'download_url' => $download_url
    ];
}

$latest_info = getLatestVersion();
$has_update = version_compare($latest_info['version'], $current_version, '>');
?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title><?php echo htmlspecialchars($settings['title']); ?> - 控制面板</title>
    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <link rel="stylesheet" type="text/css" href="../assets/css/materialdesignicons.min.css">
    <link rel="stylesheet" type="text/css" href="../assets/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../assets/css/animate.min.css">
    <link rel="stylesheet" type="text/css" href="../assets/css/style.min.css">
    <style>
        /* 移动端表格优化 */
        @media (max-width: 767.98px) {
            .table-responsive {
                overflow-x: auto;
                -webkit-overflow-scrolling: touch;
            }
            
            .table-nowrap th, 
            .table-nowrap td {
                white-space: nowrap;
            }
            
            /* 表格内容紧凑显示 */
            .table-sm th, 
            .table-sm td {
                padding: 0.3rem;
                font-size: 0.875rem;
            }
            
            /* 确保水平滚动条可见 */
            .table-responsive-sm {
                position: relative;
            }
            
            /* 最近查询记录表格特别处理 */
            .query-logs-table th,
            .query-logs-table td {
                min-width: 80px;
            }
            
            /* 移动端按钮组优化 */
            .mobile-btn-group {
                display: flex;
                flex-direction: column;
                gap: 10px;
            }
            
            .mobile-btn-group .btn {
                width: 100%;
                margin: 0 !important;
            }
        }
    </style>
</head>

<body>
<!--页面loading-->
<div id="lyear-preloader" class="loading">
    <div class="ctn-preloader">
        <div class="round_spinner">
            <div class="spinner"></div>
            <img src="../assets/images/loading-logo.png" alt="">
        </div>
    </div>
</div>
<!--页面loading end-->

<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <?php $current_page = 'index'; include 'navbar.php'; ?>
        
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid p-t-15">
                <div class="row">
                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-primary">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">卡密总数</p>
                                    <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $total_cards; ?></p>
                                </div>
                                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-key-variant fa-1-5x"></i></span> </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-danger">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">已使用卡密</p>
                                    <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $used_cards; ?></p>
                                </div>
                                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-key-remove fa-1-5x"></i></span> </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-success">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">未使用卡密</p>
                                    <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $unused_cards; ?></p>
                                </div>
                                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-key-plus fa-1-5x"></i></span> </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-info">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">查询记录</p>
                                    <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $total_logs; ?></p>
                                </div>
                                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-database-search fa-1-5x"></i></span> </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-header">
                                <h4>最近生成的卡密</h4>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive-sm">
                                    <div class="table-responsive">
                                        <table class="table table-hover table-nowrap">
                                            <thead>
                                                <tr>
                                                    <th>卡密</th>
                                                    <th>类型</th>
                                                    <th>使用时间</th>
                                                    <th>到期时间</th>
                                                    <th>状态</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                 <?php if (!empty($recent_cards)): ?>
                                                     <?php foreach ($recent_cards as $card): ?>
                                                         <tr>
                                                             <td><?php echo htmlspecialchars($card['kami_key']); ?></td>
                                                            <td>
                                                         <?php 
                                                         // 从卡密生成时设置的值中提取时长
                                                         $duration = '';
                                                         $card_value = 0;
                                                         
                                                         if ($card['type'] == '永久卡') {
                                                             $duration = '永久';
                                                         } else {
                                                             // 提取时长值
                                                             switch ($card['type']) {
                                                                 case '分钟卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / 60);
                                                                         $duration = $card_value . '分钟';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 case '小时卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / 3600);
                                                                         $duration = $card_value . '小时';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 case '天卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / 86400);
                                                                         $duration = $card_value . '天';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 case '周卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / (604800));
                                                                         $duration = $card_value . '周';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 case '月卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / (2678400));
                                                                         $duration = $card_value . '个月';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 case '季卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / (8035200));
                                                                         $duration = $card_value . '季';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 case '年卡':
                                                                     if (!empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00') {
                                                                         $card_value = ceil((strtotime($card['expire_time']) - strtotime($card['create_time'])) / (32140800));
                                                                         $duration = $card_value . '年';
                                                                     } else {
                                                                         $duration = '未设置';
                                                                     }
                                                                     break;
                                                                 default:
                                                                     $duration = '-';
                                                             }
                                                         }
                                                         
                                                         echo htmlspecialchars($card['type']) . ' <span style="color: red;">(' . $duration . ')</span>';
                                                         ?>
                                                     </td>
                                                         <td>
                                                             <?php
                                                             if (!empty($card['first_use_time']) && $card['first_use_time'] !== '0000-00-00 00:00:00') {
                                                                 echo htmlspecialchars($card['first_use_time']);
                                                             } else {
                                                                 echo '<span class="text-muted">未激活</span>';
                                                             }
                                                             ?>
                                                         </td>
                                                         <td>
                                                             <?php
                                                             if (!empty($card['first_use_time']) && $card['first_use_time'] !== '0000-00-00 00:00:00') {
                                                                 $expire_time = null;
                                                                 switch ($card['type']) {
                                                                     case '分钟卡': $expire_time = strtotime($card['first_use_time']) + 60; break;
                                                                     case '小时卡': $expire_time = strtotime($card['first_use_time']) + 3600; break;
                                                                     case '天卡': $expire_time = strtotime($card['first_use_time']) + 86400; break;
                                                                     case '周卡': $expire_time = strtotime($card['first_use_time']) + 604800; break;
                                                                     case '月卡': $expire_time = strtotime($card['first_use_time']) + 2592000; break;
                                                                     case '季卡': $expire_time = strtotime($card['first_use_time']) + 7776000; break;
                                                                     case '年卡': $expire_time = strtotime($card['first_use_time']) + 31536000; break;
                                                                     case '永久卡': $expire_time = null; break;
                                                                     default: $expire_time = null;
                                                                 }
                                                                 if ($expire_time) {
                                                                     echo '<span style="color:red;">' . date('Y-m-d H:i:s', $expire_time) . '</span>';
                                                                 } else {
                                                                     echo '<span style="color:red;">永久</span>';
                                                                 }
                                                             } else {
                                                                 echo '<span class="text-muted">未激活</span>';
                                                             }
                                                             ?>
                                                         </td>
                                                             <td>
                                                                 <?php if ($card['status'] == 1): ?>
                                                                 <?php if (!empty($card['first_use_time']) && !empty($card['expire_time']) && $card['expire_time'] !== '0000-00-00 00:00:00' && strtotime($card['expire_time']) < time()): ?>
                                                                     <span class="badge bg-warning">已过期</span>
                                                                 <?php elseif ($card['use_count'] > 0): ?>
                                                                     <span class="badge bg-danger">已使用</span>
                                                                 <?php else: ?>
                                                                     <span class="badge bg-success">未使用</span>
                                                                 <?php endif; ?>
                                                             <?php else: ?>
                                                                 <span class="badge bg-secondary">已禁用</span>
                                                                 <?php endif; ?>
                                                             </td>
                                                         </tr>
                                                     <?php endforeach; ?>
                                                 <?php else: ?>
                                                     <tr>
                                                         <td colspan="6" class="text-center">暂无数据</td>
                                                     </tr>
                                                 <?php endif; ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-header">
                                <h4>最近查询记录</h4>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive-sm">
                                    <div class="table-responsive">
                                        <table class="table table-hover table-nowrap query-logs-table">
                                            <thead>
                                                <tr>
                                                    <th>QQ号</th>
                                                    <th>手机号</th>
                                                    <th>运营商</th>
                                                    <th>经度</th>
                                                    <th>纬度</th>
                                                    <th>地区</th>
                                                    <th>IP地址</th>
                                                    <th>查询时间</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                 <?php if (!empty($recent_logs)): ?>
                                                     <?php foreach ($recent_logs as $log): ?>
                                                         <tr>
                                                             <td><?php echo htmlspecialchars($log['qq']); ?></td>
                                                         <td><?php echo empty($log['phone']) ? '没有找到' : htmlspecialchars($log['phone']); ?></td>
                                                         <td><?php echo empty($log['phonediqu']) ? '没有找到' : htmlspecialchars($log['phonediqu']); ?></td>
                                                         <td><?php echo htmlspecialchars($log['longitude'] ?? ''); ?></td>
                                                         <td><?php echo htmlspecialchars($log['latitude'] ?? ''); ?></td>
                                                         <td><?php echo htmlspecialchars($log['region'] ?? ''); ?></td>
                                                             <td><?php echo htmlspecialchars($log['ip']); ?></td>
                                                             <td><?php echo htmlspecialchars($log['created_at']); ?></td>
                                                         </tr>
                                                     <?php endforeach; ?>
                                                 <?php else: ?>
                                                     <tr>
                                                         <td colspan="8" class="text-center">暂无数据</td>
                                                     </tr>
                                                 <?php endif; ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-lg-12">
                         <div class="card">
                             <div class="card-header">
                                 <h4>程序信息</h4>
                             </div>
                             <div class="card-body">
                                 <div class="row">
                                     <div class="col-md-6">
                                         <!-- 本机信息卡片 -->
                                         <div class="card bg-light mb-3">
                                             <div class="card-body">
                                                 <h5 class="card-title">本机信息</h5>
                                                 <ul class="list-group list-group-flush">
                                                     <li class="list-group-item">服务器：<?php echo php_uname('n'); ?></li>
                                                     <li class="list-group-item">操作系统：<?php echo php_uname('s') . ' ' . php_uname('r'); ?></li>
                                                     <li class="list-group-item">PHP版本：<?php echo PHP_VERSION; ?></li>
                                                     <li class="list-group-item">MySQL版本：<?php
                                                         $mysql_version = $pdo->query('select version()')->fetchColumn();
                                                         echo $mysql_version ? $mysql_version : '未知';
                                                     ?></li>
                                                     <li class="list-group-item">Web服务器：<?php echo $_SERVER['SERVER_SOFTWARE'] ?? '未知'; ?></li>
                                                 </ul>
                                             </div>
                                         </div>
                                     </div>
                                     <div class="col-md-6">
                                         <!-- 合并后的版本信息与更新日志卡片 -->
                                         <div class="card bg-light">
                                             <div class="card-body">
                                                 <h5 class="card-title">版本信息与更新日志</h5>
                                                 <!-- 版本信息部分 -->
                                                 <p class="card-text">当前版本：<span class="badge bg-primary"><?php echo $current_version; ?></span></p>
                                                 <p class="card-text">最新版本：<span class="badge <?php echo $has_update ? 'bg-danger' : 'bg-success'; ?>"><?php echo $latest_info['version']; ?></span></p>
                                                 <?php if ($has_update): ?>
                                                 <div class="alert alert-warning">
                                                     <i class="mdi mdi-alert"></i> 发现新版本，建议及时更新！
                                                 </div>
                                                 <?php else: ?>
                                                 <div class="alert alert-success">
                                                     <i class="mdi mdi-check-circle"></i> 当前已是最新版本
                                                 </div>
                                                 <?php endif; ?>
                                                 <?php if ($has_update): ?>
                                                 <div class="form-check mb-3">
                                                     <input class="form-check-input" type="checkbox" id="backupBeforeUpdate" checked>
                                                     <label class="form-check-label" for="backupBeforeUpdate">
                                                         更新前备份当前文件
                                                     </label>
                                                 </div>
                                                 <?php endif; ?>
                                                 <div class="btn-group d-none d-md-flex mt-3">
                                                     <a href="<?php echo $latest_info['update_url']; ?>" target="_blank" class="btn btn-info">
                                                         <i class="mdi mdi-github"></i> 访问项目仓库
                                                     </a>
                                                     <button id="check-update" class="btn btn-primary">
                                                         <i class="mdi mdi-refresh"></i> 检查更新
                                                     </button>
                                                     <?php if ($has_update): ?>
                                                     <button id="auto-update" class="btn btn-danger">
                                                         <i class="mdi mdi-cloud-download"></i> 开始更新
                                                     </button>
                                                     <?php endif; ?>
                                                 </div>
                                                 <div class="mobile-btn-group d-md-none mt-3">
                                                     <a href="<?php echo $latest_info['update_url']; ?>" target="_blank" class="btn btn-info">
                                                         <i class="mdi mdi-github"></i> 访问项目仓库
                                                     </a>
                                                     <button id="check-update-mobile" class="btn btn-primary">
                                                         <i class="mdi mdi-refresh"></i> 检查更新
                                                     </button>
                                                     <?php if ($has_update): ?>
                                                     <button id="auto-update-mobile" class="btn btn-danger">
                                                         <i class="mdi mdi-cloud-download"></i> 开始更新
                                                     </button>
                                                     <?php endif; ?>
                                                 </div>
                                                 <!-- 更新日志部分 -->
                                                 <div class="update-log p-3 mt-4" style="max-height: 200px; overflow-y: auto; background-color: #f8f9fa; border-radius: 4px;">
                                                     <pre style="white-space: pre-wrap; word-break: break-word;"><?php echo $latest_info['update_log']; ?></pre>
                                                 </div>
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                             </div>
                         </div>
                    </div>
                </div>

            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
<script type="text/javascript" src="../assets/js/popper.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../assets/js/jquery.mCustomScrollbar.concat.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../assets/js/main.min.js"></script>
<script>
$(document).ready(function() {
    // 检测是否为移动设备
    var isMobile = window.matchMedia("only screen and (max-width: 767.98px)").matches;
    
    // 移动端表格优化
    if (isMobile) {
        // 为表格添加小尺寸类
        $('.table').addClass('table-sm');
        
        // 添加表格滚动提示
        $('.table-responsive-sm').each(function() {
            if ($(this).find('table').width() > $(this).width()) {
                var $scrollHint = $('<div class="text-muted text-center mt-2"><small><i class="mdi mdi-gesture-swipe"></i> 左右滑动查看更多</small></div>');
                $(this).after($scrollHint);
                
                // 3秒后淡出提示
                setTimeout(function() {
                    $scrollHint.fadeOut(1000);
                }, 3000);
            }
        });
    }
    
    // 检查更新按钮点击事件
    $('#check-update, #check-update-mobile').click(function() {
        var $btn = $(this);
        $btn.prop('disabled', true).html('<i class="mdi mdi-loading mdi-spin"></i> 正在检查...');
        
        // 重新加载页面以获取最新版本信息
        setTimeout(function() {
            window.location.reload();
        }, 1000);
    });
    
    // 自动更新按钮点击事件
    $('#auto-update, #auto-update-mobile').click(function() {
        if (!confirm('确定要更新系统吗？更新过程中请勿关闭页面。')) {
            return;
        }
        
        var $btn = $(this);
        $btn.prop('disabled', true).html('<i class="mdi mdi-loading mdi-spin"></i> 正在更新...');
        
        // 获取是否备份选项
        var doBackup = $('#backupBeforeUpdate').is(':checked');
        
        // 显示更新进度模态框
        $('#updateProgressModal').modal('show');
        
        // 开始更新流程
        startUpdate(doBackup);
    });
    
    // 自动更新流程
    function startUpdate(doBackup) {
        // 更新进度条
        updateProgress(10, '正在下载更新包...');
        
        // 发送AJAX请求到update.php进行更新
        $.ajax({
            url: 'update.php',
            type: 'POST',
            dataType: 'json',
            data: {
                action: 'update',
                version: '<?php echo $latest_info['version']; ?>',
                download_url: '<?php echo $latest_info['download_url']; ?>',
                backup: doBackup ? 1 : 0
            },
            success: function(response) {
                if (response.success) {
                    updateProgress(100, '更新成功！页面将在3秒后刷新...');
                    setTimeout(function() {
                        window.location.reload();
                    }, 3000);
                } else {
                    updateProgress(0, '更新失败：' + response.message, 'danger');
                    $('#auto-update').prop('disabled', false).html('<i class="mdi mdi-cloud-download"></i> 开始更新');
                }
            },
            error: function() {
                updateProgress(0, '更新失败：网络错误或服务器异常', 'danger');
                $('#auto-update').prop('disabled', false).html('<i class="mdi mdi-cloud-download"></i> 开始更新');
            }
        });
    }
    
    // 更新进度条
    function updateProgress(percent, message, type) {
        type = type || 'primary';
        $('#updateProgressBar')
            .css('width', percent + '%')
            .attr('aria-valuenow', percent)
            .removeClass('bg-primary bg-success bg-danger')
            .addClass('bg-' + type);
        
        $('#updateProgressMessage').text(message);
    }
});
</script>

<!-- 更新进度模态框 -->
<div class="modal fade" id="updateProgressModal" tabindex="-1" aria-labelledby="updateProgressModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="updateProgressModalLabel">系统更新进度</h5>
            </div>
            <div class="modal-body">
                <div class="progress">
                    <div id="updateProgressBar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
                <p id="updateProgressMessage" class="mt-2 text-center">准备更新...</p>
            </div>
        </div>
    </div>
</div>
</body>
</html> 